package com.zisuyi.uilibrary.module.activty.present

import android.graphics.Color
import android.view.View
import com.weilele.mvvm.utils.activity.textFrom
import com.weilele.mvvm.utils.longTimeToStr
import com.weilele.mvvm.utils.vLaout.VLayoutHolder
import com.zisuyi.game.sdk.net.bean.RedeemHistoryBean
import com.zisuyi.uilibrary.databinding.RcvPresentBinding
import java.text.SimpleDateFormat
import java.util.*


class PresentHolder : VLayoutHolder<RedeemHistoryBean, RcvPresentBinding> {
    constructor(binding: RcvPresentBinding) : super(binding)
    constructor(itemView: View) : super(itemView)

    companion object {
        private val statusColorMap = mapOf(
            1 to "#FFFF9350",
            0 to "#FFA06D4F",
            2 to "#FF23D184",
            -1 to "#FFEC3737",
            -2 to "#FFBABABA"
        )
        private val statusMap = mapOf(
            1 to "Processing",
            0 to "Pending",
            2 to "Succeed",
            -1 to "Violation",
            -2 to "Failed"
        )
    }


    override fun bindData(data: RedeemHistoryBean) {
        data.gift.apply {
            //2021-02-01T15:10:45.44132Z
            val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault())
            val newData = sdf.parse(data.createdAt)
            mBinding.tvTitle.textFrom(longTimeToStr(newData?.time, "MM/dd/yyyy"))
            mBinding.tvMoney.textFrom("$type $symbol$amount")
            statusColorMap[data.statusCode]?.let {
                mBinding.tvStatus.setTextColor(Color.parseColor(it))
            }
            statusMap[data.statusCode]?.let {
                mBinding.tvStatus.textFrom(it)
            }
        }
    }
}